package com.kermel.andromeda.data;

import android.os.Parcel;
import android.test.AndroidTestCase;

public class CountdownTimerTest extends AndroidTestCase {
    
    public static final WhenCountdownTimerEndsChoice TIMER_ENDS_CHOICE_FIXTURE = WhenCountdownTimerEndsChoice.PLAY_SOUND;
    public static final int HOURS_FROM_NOW_FIXTURE = Integer.MAX_VALUE;
    public static final int MINUTES_FROM_NOW_FIXTURE = Integer.MIN_VALUE;
    
    private CountdownTimer countdownTimer;
    
    protected void setUp() throws Exception {
        super.setUp();
        
        countdownTimer = createCountdownTimerFixture();
    }

    protected void tearDown() throws Exception {
        countdownTimer = null;
        
        super.tearDown();
    }
    
    private CountdownTimer createCountdownTimerFixture() {
        CountdownTimer countdownTimerFixture = new CountdownTimer();
        
        countdownTimerFixture.whenCountdownTimerEndsChoice = WhenCountdownTimerEndsChoice.UNKNOWN;
        countdownTimerFixture.hoursFromNow = HOURS_FROM_NOW_FIXTURE;
        countdownTimerFixture.minutesFromNow = MINUTES_FROM_NOW_FIXTURE;
        
        return countdownTimerFixture;
    }
    
    public void testCalculateTriggerTime() {
        countdownTimer.hoursFromNow = 0;
        countdownTimer.minutesFromNow = 1;
        
        long triggerTime = countdownTimer.calculateTriggerTime();
        
        assertTrue(triggerTime > 0);
    }

    
    public void testParcelWriteAndRead() {
        
        Parcel parcel = Parcel.obtain();
        int flags = 0;
        
        CountdownTimer countdownTimerFixture = createCountdownTimerFixture();
        countdownTimerFixture.whenCountdownTimerEndsChoice = TIMER_ENDS_CHOICE_FIXTURE;
        
        countdownTimerFixture.writeToParcel(parcel, flags);
        
        parcel.setDataPosition(0);
        
        CountdownTimer countdownTimerFromParcel = new CountdownTimer(parcel);
        
        assertEquals(TIMER_ENDS_CHOICE_FIXTURE, countdownTimerFromParcel.whenCountdownTimerEndsChoice);
        assertEquals(HOURS_FROM_NOW_FIXTURE, countdownTimerFromParcel.hoursFromNow);
        assertEquals(MINUTES_FROM_NOW_FIXTURE, countdownTimerFromParcel.minutesFromNow);
        
        assertTrue(countdownTimerFromParcel.vibrate);
    }
}
